home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 10.2 KB | 487 lines | [TEXT/MPS ] |
- /*
- File: CRecordID.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <7> 2/27/95 TMH adapt to use ETO16 universal headers
- <6> 2/17/95 TMH added CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr
- recType)
- <5> 2/14/95 CL remove globals
- <4> 10/18/94 TMH added PackKeyChainRID
- <3> 10/13/94 TMH use GetDSRefNum(), big bug fix
- <2> 10/11/94 TMH added CRecordID(short pcatDSRefNum,char* recName,char* recType)
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <2> 6/14/94 TMH added RecordID* rid assignment operator
- 4/5/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
-
- #ifndef __OCE__
- #include "OCE.h"
- #endif
-
- #ifndef __OCEAUTHDIR__
- #include "OCEAuthDir.h"
- #endif
-
- #ifndef __Globals__
- #include "Globals.h"
- #endif
-
-
- #ifndef __CRecordID__
- #include "CRecordID.h"
- #endif
-
- #ifndef __CAttribute__
- #include "CAttribute.h"
- #endif
-
-
-
- //----------------------
- // C P a c k e d R L I
- //----------------------
-
-
- //-------------------------
- // C R e c o r d I D
- //-------------------------
-
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(short pcatDSRefNum, CreationID cid)
- {
- this->Initialize();
- fCID = cid;
-
-
- _fPackedRLI.fDSRefNum = pcatDSRefNum;
-
- }
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(short pcatDSRefNum,char* recName,char* recType)
- {
- this->Initialize();
-
- _fRecordName = recName;
- _fRecordType = recType;
-
- _fPackedRLI.fDSRefNum = pcatDSRefNum;
-
- }
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr recType)
- {
- this->Initialize();
-
- _fRecordName = recName;
- _fRecordType = recType;
-
- _fPackedRLI.fDSRefNum = pcatDSRefNum;
-
- }
-
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(CRecordID& cRID)
- {
- // Caution should work with a RecordID* cast to be CRecordID&
- this->Initialize();
-
- if( cRID.fName != 0 )
- _fRecordName = *cRID.fName;
-
- if( cRID.fType != 0 )
- _fRecordType = *cRID.fType;
-
- fCID = cRID.fCID;
- BlockMove(cRID.fRLI,fRLI,sizeof(CPackedRLI));
- }
-
-
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(PackedDSSpecPtr packedDSSpec)
- {
- extern DNodeNum MapPathNameToDNode(RLI *aRLI,short dsRefNum); // From ADASUtils.h
-
-
- this->Initialize();
-
- this->SetFromPackedDSSpec(packedDSSpec);
-
- }
-
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(CRLI& rli,CRecordName& recordName,CRecordType& recordType)
- {
- this->Initialize();
-
- OCEPackRLI((RLI*)&rli,*fRLI,sizeof(CPackedRLI));
-
- _fRecordName = recordName;
- _fRecordType = recordType;
-
- }
-
-
- //------------------------------------------------------------------------------------------
- CRecordID::CRecordID(short dsRefNum, PackedRecordID* packedRecordID)
- {
- this->Initialize();
-
- RecordID rid;
- OCEUnpackRecordID(packedRecordID,&rid);
-
- _fRecordName = rid.local.recordName; // copy
-
- _fRecordType = rid.local.recordType; // copy
-
- fCID = rid.local.cid;
-
- _fPackedRLI.fDSRefNum = dsRefNum;
-
- }
-
-
-
- //------------------------------------------------------------------------------------------
- void CRecordID::Initialize()
- {
- memset(this,0,sizeof(CRecordID));
-
- fRLI = &_fPackedRLI;
- fName = &_fRecordName;
- fType = &_fRecordType;
-
- }
-
-
-
-
- //------------------------------------------------------------------------------------------
- CRecordID& CRecordID::operator =(CRecordID& cRID)
- {
- if( cRID.fName != 0 )
- _fRecordName = *cRID.fName;
-
- if( cRID.fType != 0 )
- _fRecordType = *cRID.fType;
-
- fCID = cRID.fCID;
- BlockMove(cRID.fRLI,fRLI,sizeof(CPackedRLI));
- return *this;
- }
-
-
-
- //------------------------------------------------------------------------------------------
- CRecordID& CRecordID::operator =(RecordID* rid)
- {
- if( rid->local.recordName != 0 )
- _fRecordName = rid->local.recordName;
-
- if( rid->local.recordType != 0 )
- _fRecordType = rid->local.recordType;
-
- fCID = rid->local.cid;
- BlockMove(rid->rli,fRLI,sizeof(CPackedRLI));
- return *this;
- }
-
-
- //-------------------------------------------------------------
- KeyChainPackedRIDPtr CRecordID::PackKeyChainRID(KeyChainPackedRIDPtr pRID)
- {
- RecordID rid;
- rid.rli = 0;
- rid.local.recordName = 0;
- rid.local.recordType = 0;
- rid.local.cid.source = fCID.source;
- rid.local.cid.seq = fCID.seq;
-
- OCEPackRecordID(&rid,(PackedRecordID*) pRID, kKeyChainPackedRIDSize);
-
- return pRID;
-
- }
-
- //-------------------------------------------------------------
- void CRecordID::SetFromPackedDSSpec(PackedDSSpecPtr packedDSSpec)
- {
- extern DNodeNum MapPathNameToDNode(RLI *aRLI,short dsRefNum); // From ADASUtils.h
-
- RecordID aRID;
- DSSpec dsspec;
-
- OCEUnpackDSSpec(packedDSSpec, &dsspec, &aRID);
-
- RLI aRLI;
- OCEUnpackRLI (aRID.rli, &aRLI);
-
- if( aRLI.dNodeNumber == 0 ) // if it is a packed pathname map it to the dNodeNumber.
- MapPathNameToDNode(&aRLI,0); // not well tested
-
-
- // copy the values
-
-
- if( aRLI.dNodeNumber != 0 ) {
- _fPackedRLI = &aRLI;
- _fRecordName = aRID.local.recordName;
- _fRecordType = aRID.local.recordType;
- fCID = aRID.local.cid;
- }
-
- }
-
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::GetNameAndType()
- {
- // CAUTION! This may change the name of this record.
- DirGetNameAndTypePB pb;
- memset(&pb, 0, sizeof(DirGetNameAndTypePB)); // Build Packed Path Name from dNodePath
-
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.ioCompletion = nil;
-
- pb.aRecord = *this;
-
- return DirGetNameAndType((DirParamBlock*)&pb, false);
-
- }
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::SetNameAndType( Boolean allowDups)
- {
- // CAUTION! This may change the name of this record.
- DirSetNameAndTypePB pb;
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.ioCompletion = nil;
-
- pb.aRecord = *this;
- pb.allowDuplicate = allowDups;
- pb.newName = (RString*)&_fRecordName;
- pb.newType = (RString*)&_fRecordType;
-
- return DirSetNameAndType((DirParamBlock*)&pb, false);
-
- }
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::AddAsPseudoNym(Boolean allowDuplicate)
- {
- DirAddPseudonymPB pb;
- memset(&pb,sizeof(DirAddPseudonymPB),0);
-
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.allowDuplicate = allowDuplicate; // will give dup error if record or pseudonym exists.
-
- pb.aRecord = *this;
-
- pb.pseudonymName = (RString*)&_fRecordName;
- pb.pseudonymType = (RString*)&_fRecordType;
-
- return DirAddPseudonym((DirParamBlockPtr)&pb, false);
- }
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::DeletePseudoNym()
- {
- DirDeletePseudonymPB pb;
- memset(&pb,sizeof(DirDeletePseudonymPB),0);
-
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.aRecord = *this;
-
-
- // We assume that no grief is caused by the record name.
-
-
- pb.pseudonymName = (RString*)&_fRecordName;
- pb.pseudonymType = (RString*)&_fRecordType;
-
- return DirDeletePseudonym((DirParamBlockPtr)&pb, false);
- }
-
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::Delete()
- {
-
-
- DirDeleteRecordPB pb;
- memset(&pb,sizeof(DirDeleteRecordPB),0);
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.aRecord = *this;
- return DirDeleteRecord((DirParamBlockPtr)&pb, false);
- }
-
-
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::Create(Boolean allowDuplicate)
- {
-
-
- DirAddRecordPB pb;
- memset(&pb,sizeof(DirAddRecordPB),0);
-
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
- pb.aRecord = *this;
-
- pb.allowDuplicate = allowDuplicate;
-
- return DirAddRecord((DirParamBlockPtr)&pb, false);
-
-
- }
-
-
- //-------------------------------------------------------------
- OSErr CRecordID::CreateAsAlias(CRecordID& origRID, Boolean allowDuplicate,long /*backPtrFlags*/)
- {
-
- // Create the alias record in catalog server.
-
-
- DirAddAliasPB pb;
- memset(&pb,sizeof(DirAddAliasPB),0);
- pb.dsRefNum = this->GetDSRefNum();
- pb.identity = gIdentity;
-
- long nilHint = 0;
- pb.serverHint = *(AddrBlock*)&nilHint;
-
-
- pb.aRecord = *this;
- pb.allowDuplicate = allowDuplicate;
- OSErr osErr = DirAddAlias((DirParamBlockPtr)&pb, false);
-
-
- if( osErr == 0 ) {
-
- PackedDSSpec** packedDSSpec = 0;
-
- // Create the alias attribute.
-
- packedDSSpec = (PackedDSSpec**) origRID.PackDSSpec();
- CAttribute aliasAttr( kAliasAttrTypeNum, typePackedDSSpec );
- aliasAttr.fDataLength =(*packedDSSpec)->dataLength + sizeof(short);
- aliasAttr.fBytes = (void *)*packedDSSpec;
-
- osErr = aliasAttr.AddAttribute( *this ) ;
-
- #ifdef ALIASBACKPOINTERS
- if( osErr == 0 ) {
-
-
- // Alias Backpointer
-
-
- AliasBackpointer bp;
- bp.cid = fCID;
- bp.node = this->Node();
- bp.flags = backPtrFlags;
- CAttribute backpointerAttr( kAliasBackPointerTypeNum, typeBinary );
- backpointerAttr.fDataLength = sizeof(AliasBackpointer);
- backpointerAttr.fBytes = (void *)&bp;
- osErr = backpointerAttr.AddAttribute( origRID );
-
-
- }
-
- #endif
- if( osErr != 0 )
- this->Delete();
-
- if( packedDSSpec != 0 )
- DisposeHandle((Handle)packedDSSpec);
-
-
- }
-
- return osErr;
-
- }
-
-
-
- //-------------------------------------------------------------
- PackedDSSpec** CRecordID::PackDSSpec()
- {
-
- // Caller is responsible for Disposing result.
-
-
- DSSpec aliasDSSpec;
- aliasDSSpec.entitySpecifier = *this;
- aliasDSSpec.extensionType = kOCEentnDSSpec;
- aliasDSSpec.extensionSize = 0;
- aliasDSSpec.extensionValue = 0;
-
- unsigned short packedDSSpecLen = OCEPackedDSSpecSize (&aliasDSSpec);
- PackedDSSpec** packedDSSpec = (PackedDSSpec**) NewHandle(packedDSSpecLen);
-
- OCEPackDSSpec (&aliasDSSpec, *packedDSSpec, packedDSSpecLen);
-
- return packedDSSpec;
- }
-
-
-
-